package com.qcby.Controller;

import com.qcby.Entity.TrainStation;
import com.qcby.Service.TrainStationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/TrainStation")
public class TrainStationController {

    @Autowired
    private TrainStationService trainStationService;

    @CrossOrigin
    @GetMapping("/getTrainStationById")
    public TrainStation getTrainStationById(Integer id) {

        return trainStationService.selectByPrimaryKey(id);
    }

    @CrossOrigin
    @PostMapping("/insertSation")
    public TrainStation createCity(@RequestBody TrainStation demo) {
        trainStationService.insert(demo);
        return demo;
    }

    @CrossOrigin
    @PutMapping("/updateTrainStation")
    public TrainStation updateTrainStation(@RequestBody TrainStation demo) {
        trainStationService.updateByPrimaryKey(demo);
        return demo;
    }

    @DeleteMapping("/deleteTrainStation")
    public void deleteTrainStation(@PathVariable Integer id) {
        trainStationService.deleteByPrimaryKey(id);
    }

    @CrossOrigin
    @RequestMapping("/getStationNumByStationName")
    public int getStationNumByStationName(TrainStation trainStation){
        return trainStationService.getStationNumByStationName(trainStation);
    }

    @CrossOrigin
    @RequestMapping("/getAllStations")
    public List<TrainStation> getAllStations(){
        return trainStationService.getAllStations();
    }
}
